package file;

import java.io.*;
import java.util.Scanner;

public class Demo2 {
    public static void main(String[] args) {
        Scanner scanner=new Scanner(System.in);
        System.out.println("请输入要复制的源文件");
        String src=scanner.next();
        System.out.println("请输入要复制的目标文件");
        String dest=scanner.next();

        File srcFile=new File(src);
        if(!srcFile.isFile()){
            System.out.println("当前输入的路径有误，不是一个合法文件");
            return;
        }
        try(InputStream inputStream=new FileInputStream(src)){
            try(OutputStream outputStream=new FileOutputStream(dest)){
                byte[] buffer=new byte[1024];
                while (true){
                    int len=inputStream.read(buffer);
                    if(len==-1){
                        break;
                    }
                    outputStream.write(buffer,0,len);
                }
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
